package com.shk.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shk.dao.Log4jDao;
import com.shk.entity.PageResult;
import com.shk.entity.QueryPageBean;
import com.shk.entity.Result;
import com.shk.pojo.Log4j2Db;
import com.shk.service.Log4jService;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class Log4jServiceImp implements Log4jService {
    @Autowired
    private Log4jDao log4jDao;
    @Override
    public void addLog2Db(Log4j2Db log) {
        log4jDao.add(log);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        Page<Object> page = PageHelper.startPage(currentPage, pageSize);
        log4jDao.findAllLog(queryString);
        PageInfo<Object> info = new PageInfo<>(page);
        PageResult pageResult = new PageResult(info.getTotal(), info.getList());
        return  pageResult;
    }

    @Override
    public void deleteById(Integer id) {
        log4jDao.deleteById(id);
    }

}
